package top.hkyzf.study.leetcode.array;

import org.junit.Test;

/**
 * @author zhufeng
 * @version 1.0
 * @date 2022-1-13 22:10
 */
public class 提莫攻击_495 {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int total = 0;
        int end = 0;
        for (int current : timeSeries) {
            // 计算上次的结束是否大于当前值，大于的话需要减去差值，否则将差值按照 0 计算
            int diff = end - current;
            if (diff < 0) {
                diff = 0;
            }
            total = total - diff + duration;
            end = current + duration;
        }
        return total;
    }

    @Test
    public void testFindPoisonedDuration () {
        int [] timeSeries = new int[]{1, 4, 7, 9};
        int duration = 4;
        int poisonedDuration = findPoisonedDuration(timeSeries, duration);
        System.out.println(poisonedDuration);
    }
}
